import { ref } from "vue"
import { defineStore } from "pinia"

export const useUserStore = defineStore(
  "user",
  () => {
    //保存用户信息,持久化
    const user = ref({
      token: "",
      username: "",
      type: 0,
      id: 0,
      password: "",
    })
    // const doubleCount = computed(() => count.value.count * 2)
    function saveUser(token, username, type, id, password) {
      user.value.token = token
      user.value.username = username
      user.value.type = type
      user.value.id = id
      user.value.password = password
    }
    function changeToken(token) {
      user.value.token = token
    }
    return { user, saveUser, changeToken }
  },
  {
    persist: {
      enabled: true,
      encryptionKey: "user",
      storage: localStorage,
    },
  }
)
